<template>
  <div ref="daily" id="aleftboxtbott1" class="amiddboxtbott1content"></div>
</template>

<script>
import { ref, onMounted, watch } from "vue";

import { useECharts } from "@/hooks/useECharts";

export default {
  name: "daily_chart",
  props: {
    echartData: Object
  },
  setup(props, ctx) {
    const daily = ref(null);
    const { setOptions } = useECharts(daily, ctx);

    onMounted(() => {
      drawEchart(props.echartData)
    });

    const drawEchart = (options) => {
      if(!options.line) return;
      let lineData = options.line.map(item => {
        return {
            name: item.name,
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: item.data,
          }
      })
      setOptions({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          textStyle: {
            color: options.fontColor || '#fff',
          },
          data: options.legend,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
              color: "#fff",
            },
          },
          backgroundColor: "rgba(0,0,0,0.8)",
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: options.x_axis,
            color: "#fff",
          },
        ],
        yAxis: [
          {
            type: "value",
            color: "#fff",
          },
        ],
        series: lineData,
      });
    }

    watch(props, (val)=> {
      drawEchart(val.echartData)
    },{ deep: true , immediate: true })

    return {
      daily,
    };
  },
};
</script>


<style scoped>
.amiddboxtbott1content {
  width: 91%;
  height: 86.5%;
  margin-left: 4.8%;
  margin-top: 1.6%;
}
</style>